package com.cqc.jdk8.Jutil.stream.findMatch;

import org.junit.Before;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

/**
 * anyMatch() allMatch noneMatch 返回boolean
 */
public class MatchTest {


    List<String> stringList = null;
    List<Boolean> booleanList = null;

    @Before
    public void before() {
        stringList = getStringList();
        booleanList = getBooleanList();
    }

    @Test
    public void f2() {
        boolean flag = booleanList.stream()
                .allMatch(x -> x.equals(true));
        System.out.println(flag);
    }

    @Test
    public void f1() {
        boolean a = stringList.stream()
                .anyMatch(s -> s.startsWith("a"));
        System.out.println(a);

        boolean b = stringList.stream()
                .allMatch(s -> s.startsWith("a"));
        System.out.println(b);

        boolean c = stringList.stream()
                .noneMatch(s -> s.startsWith("z"));
        System.out.println(c);
    }


    private static List<String> getStringList() {
        List<String> strList = new ArrayList<>();
        strList.add("a1");
        strList.add("a2");
        strList.add("b1");
        strList.add("b2");
        strList.add("b3");
        strList.add("c1");
        strList.add("d1");
        strList.add("d2");
        return strList;
    }

    private static List<Boolean> getBooleanList() {
        List<Boolean> list = new ArrayList<>();
        list.add(true);
        list.add(true);
        list.add(true);
        list.add(true);
        list.add(false);
        return list;
    }

}
